﻿if (typeof Axis == "undefined") Axis = {};
if (typeof Axis.Web == "undefined") Axis.Web = {};
Axis.Web.Main = {
    Init: function () {
        var thisObj = this;
        $('#Gift-Slider').jshowoff({
            animatePause: true,
            autoPlay: true,
            changeSpeed: 2000,
            controls: false,
            controlText: {
                play: 'Play',
                pause: 'Pause',
                next: 'Next',
                previous: 'Previous'
            },
            effect: 'random',
            hoverPause: false,
            links: true,
            speed: 7000
        });
        thisObj.DialogAboutUs.Init();
        thisObj.DialogContactUs.Init();
        thisObj.DialogPolicy.Init();
        thisObj.Event();
    },
    MenuActive: function (index) {
        var $li = $(".dcjq-mega-menu ul.nav-top > li").eq(index);
        var color = $li.attr("color");
        var bgColor = "background-" + color;
        $li.addClass(bgColor + " selected");
        $(".main-separator").each(function () {
            $(this).find("ul li").css("width", "5%");
            $(this).find("ul li").eq(index).addClass("selected").css("width", "80%");
        });
        //$(".main-separator").find("ul li").css("width", "5%");
        //$(".main-separator").find("ul li").eq(index).addClass("selected").css("width", "80%");
    },
    Event: function () {
        $(".user-register").click(function () {
            ShowDialogRegister();
        });
        $(".user-login").click(function () {
            ShowDialogLogin();
        });
        $(".main-user-logged-logout").click(function () {
            var overlay = new COverlay({
                autoShow: false
            });
            overlay.Init();
            $.Ajax({
                url: "../Accounts/Service/AccountService.asmx/Logout",
                type: 'POST',
                data: {},
                success: function (data, textStatus, xhr) {
                    if (data) {
                        data = $(data).find("string").text();
                        window.location.href = "../../Views/Home";
                    }
                    overlay.Hide();
                },
                beforeSend: function () {
                    overlay.Show();
                },
                error: function (xhr, textStatus, errorThrown) {
                    overlay.Hide();
                }
            });
        });
        $("#Gift-Slider").find(".jshowoff-item").live("click", function () {
            var projectID = $(this).attr("projectid");
            switch (projectID) {
                case "97":
                case "52":
                case "50":
                    $.CAlert.Alert({
                        Title: "Thông báo",
                        Content: $.string.Format('Dự án đã hết hạn hoặc đã đủ số lượng người tham dự. Mời bạn đến dự án khác.', 1)
                    });
                    return false;
                   
            }


            if (projectID != "0")
                window.location.href = "/Views/Project/Project.aspx?ProjectID=" + projectID;
        })
    },
    DialogAboutUs: {
        Instance: null,
        Init: function () {
            var thisObj = this;
            var _width = 600
            var left = ($(window).width() - _width) / 2;
            thisObj.Instance = new CDialog({
                title: "• Giới thiệu •",
                width: _width,
                zIndex: 999,
                autoOpen: false,
                draggable: false,
                position: [left, 10],
                height: 600,
                open: function () {
                    // if ($("#FormAboutUs").html().length == "") {
                    //                        var url = window.location.href;
                    //                        var arr = url.split("/"); ;
                    //                        var result = arr[0] + "//" + arr[2];

                    $.Ajax({
                        type: "POST",
                        url: '../News/Service/NewsService.asmx/GetNewStatitic',
                        cache: false,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        data: '{' + $.string.Format('"ID":1', '') + '}',
                        success: function (pData) {
                            if (pData !== null)
                                if (pData.d !== null) {
                                    var data = eval("(" + pData.d + ")");
                                    $("#FormAboutUs").html(data[0].Content);
                                }
                        }
                    });
                    //  }
                },
                beforeClose: function (event, ui) {

                }
            });
            thisObj.Instance.Init("#FormAboutUs");
        },
        Open: function () {
            var thisObj = this;
            if (thisObj.Instance)
                thisObj.Instance.Open();
        },
        Close: function () {
            var thisObj = this;
            if (thisObj.Instance)
                thisObj.Instance.Close();
        }
    },
    DialogContactUs: {
        Instance: null,
        Init: function () {
            var thisObj = this;
            var _width = 600
            var left = ($(window).width() - _width) / 2;

            thisObj.Instance = new CDialog({
                title: "• Liên hệ •",
                width: 600,
                zIndex: 999,
                height: 600,
                autoOpen: false,
                draggable: false,
                position: [left, 10],
                open: function () {
                    // if ($("#FormAboutUs").html().length == "") {
                    //                        var url = window.location.href;
                    //                        var arr = url.split("/"); ;
                    //                        var result = arr[0] + "//" + arr[2];

                    $.Ajax({
                        type: "POST",
                        url: '../News/Service/NewsService.asmx/GetNewStatitic',
                        cache: false,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        data: '{' + $.string.Format('"ID":3', '') + '}',
                        success: function (pData) {
                            if (pData !== null)
                                if (pData.d !== null) {
                                    var data = eval("(" + pData.d + ")");
                                    $("#FormContactUs").html(data[0].Content);
                                }
                        }
                    });
                    //  }
                },
                beforeClose: function (event, ui) {

                }
            });
            thisObj.Instance.Init("#FormContactUs");
        },
        Open: function () {
            var thisObj = this;
            if (thisObj.Instance)
                thisObj.Instance.Open();
        },
        Close: function () {
            var thisObj = this;
            if (thisObj.Instance)
                thisObj.Instance.Close();
        }
    },

    DialogPolicy: {
        Instance: null,
        Init: function () {
            var thisObj = this;
            var _width = 700
            var left = ($(window).width() - _width) / 2;

            thisObj.Instance = new CDialog({
                title: "• Điều khoản •",
                width: 600,
                zIndex: _width,
                autoOpen: false,
                draggable: false,
                position: [left, 10],
                height: 600,
                open: function () {
                    // if ($("#FormAboutUs").html().length == "") {
                    //                        var url = window.location.href;
                    //                        var arr = url.split("/"); ;
                    //                        var result = arr[0] + "//" + arr[2];

                    $.Ajax({
                        type: "POST",
                        url: '../News/Service/NewsService.asmx/GetNewStatitic',
                        cache: false,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        data: '{' + $.string.Format('"ID":2', '') + '}',
                        success: function (pData) {
                            if (pData !== null)
                                if (pData.d !== null) {
                                    var data = eval("(" + pData.d + ")");
                                    $("#FormPolicy").html(data[0].Content);
                                }
                        }
                    });
                    //  }
                },
                beforeClose: function (event, ui) {

                }
            });
            thisObj.Instance.Init("#FormPolicy");
        },
        Open: function () {
            var thisObj = this;
            if (thisObj.Instance)
                thisObj.Instance.Open();
        },
        Close: function () {
            var thisObj = this;
            if (thisObj.Instance)
                thisObj.Instance.Close();
        }
    }
};
$(function () {
    Axis.Web.Main.Init();
});
function NavigationActive(index) {
    Axis.Web.Main.MenuActive(index);
}

function ShowDialogAboutUs() {
    Axis.Web.Main.DialogAboutUs.Open();
}
function ShowDialogContactUs() {
    Axis.Web.Main.DialogContactUs.Open();
}

function ShowDialogPolicy() {
    Axis.Web.Main.DialogPolicy.Open();
}